import 'package:flutter/material.dart';
import 'package:lib_uikit/lib_uikit.dart';

class GTPopMenuWidgetV3 extends StatefulWidget {
  final List<GTPopMenuModalV3> list;
  final double? width;
  final ValueChanged<GTPopMenuModalV3>? onItemClicked;

  const GTPopMenuWidgetV3({
    super.key,
    required this.list,
     this.width,
    this.onItemClicked,
  });

  @override
  State<StatefulWidget> createState() => _PopMenuStateV3();
}

class _PopMenuStateV3 extends State<GTPopMenuWidgetV3> {
  int _index = -1;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      // width: widget.width == 0 ? double.infinity : widget.width,
      decoration: BoxDecoration(
        borderRadius: const BorderRadius.all(Radius.circular(4)),
        color: GTColorsV3.cmpt16.color,
        boxShadow: [
          BoxShadow(
            color: GTColorsV3.pop_menu_shadow.color.withOpacity(0.06),
            spreadRadius: 2,
            blurRadius: 4,
            offset: Offset(0, 4),
          ),
        ],
      ),
      padding: const EdgeInsets.symmetric(vertical: 4),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Wrap(
            direction: Axis.vertical,
            runSpacing: 4.0, // 垂直间距
            children: List<Widget>.generate(widget.list.length, (index) {
              return GestureDetector(
                onTap: () {
                  setState(() {
                    _index = index;
                  });
                  widget.onItemClicked?.call(widget.list[index]);
                },
                child: Container(
                  color: GTColorsV3.cmpt16.color,
                  padding: const EdgeInsets.symmetric(
                    vertical: 8,
                    horizontal: 12,
                  ),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      if (widget.list[index].icon != null) ...[
                        Icon(
                          widget.list[index].icon,
                          color: widget.list[index].iconColor ?? GTColorsV3.icon1.color,
                          size: 14,
                        ),
                        const SizedBox(width: 8),
                      ],
                      Text(
                        widget.list[index].text,
                        style: gtTextStyleW500(
                            fontSize: 12, color: _index == index ? GTColorsV3.text5.color : GTColorsV3.text1.color),
                      ),
                    ],
                  ),
                ),
              );
            }),
          )

        ],
      ),

    );
  }
}

class GTPopMenuModalV3 {
  final String text;
  final IconData? icon;
  final Color? iconColor;

  GTPopMenuModalV3({required this.text, this.icon, this.iconColor});
}
